package edu.sctu.lab03;

import com.sun.corba.se.impl.orb.DataCollectorBase;
import org.jcp.xml.dsig.internal.dom.DOMPGPData;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * Created by dell on 2018/5/31.
 */
public class UserListServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        super.doGet(req, resp);


//JSP中没有任何java代码，，所以从userlist中转到这里

        Database database = new Database();
        List<User> userList= database.getUserList();

        // EL表达式涉及到的所有变量必须在四块空间里面定义。
        req.setAttribute("userList", userList);

        req.getRequestDispatcher("/userList.jsp")
                .forward(req, resp);//转发,先访问servlet再访问jsp
    }
}
